package com.tansun.easycare.rule.common.service;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

@Component
@Lazy(false)
public class SpringInstanceUtils implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    public static SpringInstanceUtils instance = new SpringInstanceUtils();
    


    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringInstanceUtils.applicationContext = applicationContext;

    }

    public Object getSpringBean(String beanName) {
        return SpringInstanceUtils.applicationContext.getBean(beanName);
    }
    
    public Object  getBean(Class<?> clazz) {
    	return SpringInstanceUtils.applicationContext.getBean(clazz);
    }
    
    public  Resource    getResource(String clasPath) {
    	return SpringInstanceUtils.applicationContext.getResource(clasPath);
    }

}
